package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetDetailMessegerRequest;
import keeto.com.vn.bms.network.response.GetDetailMessegerResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetDetailMesseger extends AbstractTask {

	private String msgId;
	private String AuthKey;
	private int pageLimit;
	private int pageNumber;
	

	public TaskGetDetailMesseger(BMSListener listener, IBMSCore core,
			String msgId, String authKey,int pageLimit,int pageNumber) {
		super(listener, core);
		this.msgId = msgId;
		this.AuthKey = authKey;
		this.pageLimit = pageLimit;
		this.pageNumber = pageNumber;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetDetailMessegerRequest request = new GetDetailMessegerRequest();
		request.setMsgId(msgId);
		request.setAuthkey(AuthKey);
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		GetDetailMessegerResponse response = protocol.getDetailMesseger(request);
		for (BMSListener mlistener : listener){
			mlistener.finishGetDetailMesseger(response.getReturnCode(),response.getPageCount(),response.getListMsg());
		}
		
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishGetDetailMesseger(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, IBMSConfig.UNINITIALIZED_INT,null);
		}
	}

}
